package com.vhall.component.service.lottery.delay;

import com.vhall.component.entity.lottery.vo.LotteryV4AddReqVO;
import com.vhall.component.service.vote.delay.DelayEvent;
import lombok.Data;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @author jingwen.li
 */
@Data
public class LotteryDelayEvent implements Delayed {
    private long lotteryId;

    private String roomId;

    private long delayTime;

    private Integer accountId;

    private LotteryV4AddReqVO reqParam;

    private String requestUrl;
    public LotteryDelayEvent(long lotteryId, long delayTime, String roomId, String requestUrl) {
        super();
        this.lotteryId = lotteryId;
        // 延迟时间加当前时间
        this.delayTime = System.currentTimeMillis() + delayTime * 1000;
        this.roomId = roomId;
        this.requestUrl = requestUrl;
    }

    @Override
    public long getDelay(@NotNull TimeUnit unit) {
        return unit.convert(delayTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(@NotNull Delayed o) {
        return Long.compare(delayTime, ((LotteryDelayEvent) o).delayTime);
    }
}
